package graph;

import graph.chart.point.decorator.PointDecorator;

import java.util.ArrayList;


/***
 * A simple set of points to draw on the graph
 * @author malpka
 *
 */
public class PlotSet {
	
	private double maxXValue = 0;
	private double minXValue = 0;
	private double maxYValue = 0;
	private double minYValue = 0;
	private boolean recalculateExtremumValues = true;
	
	private ArrayList<Point> points = new ArrayList<Point>();
	/* X axis mirror */
	private boolean xAxisMirrorEnabled = false;
	/* point decorator */
	private PointDecorator pointDecorator = null;
	
	
	public ArrayList<Point> getPoints() {
		return points;
	}

	public void setPoints(ArrayList<Point> points) {
		this.points = points;
	}
	
	public PointDecorator getPointDecorator() {
		return pointDecorator;
	}

	public void setPointDecorator(PointDecorator pointDecorator) {
		this.pointDecorator = pointDecorator;
	}

	public void addPoint(Point point){
		points.add(point);
	}
	
	private void recalculateExtremumValues(){
		boolean first = true;
		
		for(Point point : points){
			if(first){
				maxXValue = point.getX();
				minXValue = maxXValue;
				maxYValue = point.getY();
				minYValue = maxYValue;
				first = false;
			}else{
				if(point.getX() > maxXValue){
					maxXValue = point.getX();
				}
				if(point.getX() < minXValue){
					minXValue = point.getX();
				}
				if(point.getY() > maxYValue){
					maxYValue = point.getY();
				}
				if(point.getY() < minYValue){
					minYValue = point.getY();
				}
			}
		}
		recalculateExtremumValues = false;
	}
	
	
	public double getMaxXValue() {
		if(recalculateExtremumValues){
			recalculateExtremumValues();
		}
		return maxXValue;
	}

	public double getMinXValue() {
		if(recalculateExtremumValues){
			recalculateExtremumValues();
		}
		return minXValue;
	}

	public double getMaxYValue() {
		if(recalculateExtremumValues){
			recalculateExtremumValues();
		}
		return maxYValue;
	}

	public double getMinYValue() {
		if(recalculateExtremumValues){
			recalculateExtremumValues();
		}
		return minYValue;
	}
	
	public boolean isxAxisMirrorEnabled() {
		return xAxisMirrorEnabled;
	}

	public void setxAxisMirrorEnabled(boolean xAxisMirrorEnabled) {
		this.xAxisMirrorEnabled = xAxisMirrorEnabled;
	}
}
